package com.prs.crm.dao.oa.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.oa.ArticleDao;
import com.prs.crm.domain.oa.Article;
import com.prs.crm.domain.oa.ArticleType;
import com.sun.org.apache.bcel.internal.generic.NEW;

public class ArticleDaoImpl extends BaseDaoImpl<Article> implements ArticleDao{

	@Override
	public List<Article> getArticle() {
		Criteria criteria = this.getSession().createCriteria(Article.class);
		criteria.setMaxResults(20);
		criteria.addOrder(Order.desc("recordTime"));
		List<Article> r= criteria.list();
		if(r.size()!=0){
			return r;
		}else{
			return null;
		}
	}

	@Override
	public List<Article> getDateArticleByType(ArticleType type) {
		Criteria criteria = this.getSession().createCriteria(Article.class);
		criteria.add(Restrictions.eq("type", type));
//		criteria.add(Restrictions.eq("recordTime", new Date()));
		criteria.addOrder(Order.desc("recordTime"));
		List<Article> r= criteria.list();
		if (r==null || r.size()==0) {
			return null;
		}
		return r;
	}

}
